/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSArticulo;

import Entidades.Revision.Palabrasclave;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Nory (L)
 */
@Stateless
@LocalBean
public class PalabrasclaveDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    EntityManager em;
    public void crear(Palabrasclave pc) {
        em.persist(pc);
    }

    public void actualizar(Palabrasclave pc) {
        em.merge(pc);
    }

    public void borrar(Integer id) {
        Palabrasclave pclv = em.find(Palabrasclave.class, id);
        em.remove(pclv);
    }

    public void guardar(Palabrasclave pc) {
        if (pc.getIdPalabrasClave() == null) {
            crear(pc);
        } else {
            actualizar(pc);
        }
    }

    public List<Palabrasclave> BuscarTodos() {
        return em.createNamedQuery("Palabrasclave.findAll", Palabrasclave.class).getResultList();
    }

    public List<Palabrasclave> BuscarPalabraClave(String cadena) {
        return em.createNamedQuery("Palabrasclave.findBypalabra", Palabrasclave.class)
                .setParameter("palabra", cadena).getResultList();
    }
}
